import { defineStore } from "pinia";
import axios from "axios";
import type { passwordData, userData ,articleData} from "@/modules/users";
import { update } from "lodash-es";
export const useLoginStore = defineStore("login", {
  state: () => ({
    isLogin: false,
    userLevel:'2',
    name:"",
    accountId:"",
    articleContent:""
  }),
  actions: {
    async commonLogin(userData:userData){
      const transData={
        account:userData.account,
        password:userData.password,
        // userType:parseInt(userData.userType)

      }
      const response = await axios.post("http://192.168.1.8:8000/userslogin", transData);
      console.log(response.data.data);
      
      return response;
    },
    async administorLogin(userData:userData){
      const transData={
        account:userData.account,
        password:userData.password,
        // userType:parseInt(userData.userType)
      }
      const response = await axios.post("http://192.168.1.8:8000/login", transData);
      return response;
    },
    async userRegister(userData:userData){
      const transData={
        account:userData.account,
        password:userData.password,
        name:userData.nickName,
      }
      const response = await axios.post("http://192.168.1.8:8000/usersregister", transData);
      
      return response;
    },
    async updatePassword(passwordData:passwordData){
      const response = await axios.put("http://192.168.1.8:8000/updatePassword", passwordData);
      console.log(response.data.data);
      return response;
    },
    async createArticle(articleData:articleData){
      const response = await axios.post("http://192.168.1.8:8000/createArticle", articleData);
      return response
    }
  },
  persist: true
})